package com.example.superoa.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.example.superoa.model.pojos.Rsap;
import com.example.superoa.model.pojos.Staff;
import com.example.superoa.model.service.RsapsService;
import com.example.superoa.model.vo.RsapsVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Controller
public class RsapsController {
	@Autowired
	private RsapsService rsapservice;
	
	//详情页面
	@RequestMapping("ljj-rsaps-xq")
	public void rsapsxq() {
		
	}
	@RequestMapping("ljj-rsapsadd")
	public void rsapsadd() {
		
	}
	//查询奖惩信息
	@RequestMapping("rsaps-list")
	@ResponseBody
	public Map<String,Object> selectrsapas(int page,int rows){
		Map<String,Object> map = new HashMap<>();
		//先分页
		Page<Object> pg = PageHelper.startPage(page, rows);
		List<RsapsVo> i=rsapservice.selectrsapas();
		//总记录
		map.put("total", pg.getTotal());
		//页内容
		map.put("rows", i);
		return map;
	}
	
	//新增奖惩信息
	@PostMapping("insert-rsaps")
	public String addrsaps(Rsap rsa,Staff s) {
		rsa.setStaff(s);
		rsapservice.addrsaps(rsa,s);
		return "redirect:main-administrator:ljj-rsaps";
	}
	
	//条件查询
	@RequestMapping("select-likersaps")
	@ResponseBody
	public  Map<String,Object> selelikeke(@Param("Staff_name")String staff_name,int page,int rows) {
		Map<String,Object> map = new HashMap<>();
		//先分页
		Page<Object> pg = PageHelper.startPage(page, rows);
		JSONArray i=rsapservice.selelikeke(staff_name);
		//总记录
		map.put("total", pg.getTotal());
		//页内容
		map.put("rows", i);
		return map;
	}
	
	//根据ID获取数据
	@RequestMapping("ljj-rsapadd")
	@ResponseBody
	public String rsapsById(int rsaps_id,HttpSession session) {
		System.out.println( rsapservice.rsapsById(rsaps_id));
		session.setAttribute("rsaps", rsapservice.rsapsById(rsaps_id));
		return "";
	}
	//编辑
	@PostMapping("ljj-rsapaddbj")
	public String rsapsbjById(Rsap s) {
		s.getRsaps_Result();
		s.getRsapsTypes();
		return null;
		/*return rsapservice.rsapsbjById(s);*/
	}
	
}
